package edu.wuster.blog.controller;


import edu.wuster.blog.entity.Label;
import edu.wuster.blog.entity.Result;
import edu.wuster.blog.service.LabelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    @PostMapping("/add")
    public Result addLabel(@RequestBody Label label){
        log.info("新增博客标签");
        labelService.addLabel(label);
        log.info("新增博客标签成功");
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteLabel(@PathVariable Integer id) {
        log.info("标签(id：{})删除", id);
        labelService.deleteLabel(id);
        log.info("标签删除成功");
        return Result.success();
    }

    @GetMapping("/{blogId}")
    public Result selectById(@PathVariable Integer blogId) {
        log.info("查看博客（id:{}）的标签", blogId);
        List<Label> list = labelService.selectByBlogId(blogId);
        log.info("查看标签成功");
        return Result.success(list);
    }


}
